package com.structurizr.importer.diagrams.image;

import com.structurizr.Workspace;
import com.structurizr.http.HttpClient;
import com.structurizr.view.ImageView;
import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNull;

public class ImageImporterTests {

    @Test
    @Tag("IntegrationTest")
    public void importDiagram_Url() throws Exception {
        Workspace workspace = new Workspace("Name", "Description");
        ImageView view = workspace.getViews().createImageView("key");

        HttpClient httpClient = new HttpClient();
        httpClient.allow(".*");

        new ImageImporter(httpClient).importDiagram(view, "https://static.structurizr.com/themes/amazon-web-services-2020.04.30/alexa-for-business.png");
        assertEquals("https://static.structurizr.com/themes/amazon-web-services-2020.04.30/alexa-for-business.png", view.getContent());
        assertEquals("image/png", view.getContentType());
        assertEquals("alexa-for-business.png", view.getTitle());
    }

    @Test
    @Tag("IntegrationTest")
    public void importDiagram_Url_Inline() throws Exception {
        Workspace workspace = new Workspace("Name", "Description");
        workspace.getViews().getConfiguration().addProperty(ImageImporter.IMAGE_INLINE_PROPERTY, "true");
        ImageView view = workspace.getViews().createImageView("key");

        HttpClient httpClient = new HttpClient();
        httpClient.allow(".*");

        new ImageImporter(httpClient).importDiagram(view, "https://static.structurizr.com/themes/amazon-web-services-2020.04.30/alexa-for-business.png");
        assertEquals("", view.getContent());
        assertEquals("image/png", view.getContentType());
        assertEquals("alexa-for-business.png", view.getTitle());
    }

}